package com.tanhua.app.controller;

import com.tanhua.app.service.UserService;
import com.tanhua.db.User;
import com.tanhua.db.UserInfo;
import com.tanhua.vo.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping(value = "/saveUser",name="保存用户")
    public ResponseEntity saveUser(@RequestBody User user){
        return userService.saveUser(user);
    }

    @GetMapping(value = "/findByPhone",name="根据手机号做用户查询")
    public ResponseEntity findByPhone(String  phone){
        return userService.findByPhone(phone);
    }


    @PostMapping(value = "/login",name="手机登录发送验证码")
    public ResponseEntity login(@RequestBody Map<String,String> map){


        String phone = map.get("phone");

        return userService.login(phone);

    }
    @PostMapping(value = "/loginVerification", name = "用户登录、注册")
    public ResponseEntity loginVerification(@RequestBody Map param){
        String phone = (String) param.get("phone");
        String vCode = (String) param.get("verificationCode");
        return userService.loginVerification(phone,vCode);
    }
    @PostMapping(value = "/loginReginfo",name = "完善基本信息")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo, @RequestHeader("Authorization") String  token){
        userService.loginReginfo(userInfo,token);
        return ResponseEntity.ok(null);
    }

    @PostMapping(value = "/loginReginfo/head",name = "完善头像信息")
    public ResponseEntity loginReginfoPic(MultipartFile headPhoto, @RequestHeader("Authorization") String  token) throws Exception{
        return userService.loginReginfoPic(headPhoto,token);
    }
}
